import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.util.concurrent.TimeUnit;

public class TaoBaoTest {

    public static void main(String[] args) throws Exception {
        String filePath = System.getProperty("user.dir") + File.separator + "program" + File.separator + "chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", filePath);
        WebDriver driver = new ChromeDriver();
        //Actions action = new Actions(driver);
        //打开淘宝主页
        driver.get("https://www.taobao.com/");
        Thread.sleep(5000);

        //购物车按钮(只是为了触发去到登录页面)
        driver.findElement(By.id("mc-menu-hd")).click();
        Thread.sleep(5000);

        //选择用密码登陆
        //driver.findElement(By.id("J_Quick2Static")).click();
        //Thread.sleep(2000);

        //选择微博登陆
        driver.findElement(By.className("weibo-login")).click();
        Thread.sleep(5000);


        driver.findElement(By.className("W_btn_g")).click();
        //换为你的微博账号
        driver.findElement(By.name("username")).sendKeys(new String[]{"13622273212"});
        //换为你的微博密码
        driver.findElement(By.name("password")).sendKeys(new String[]{"11111"});
        //确认使用微博登陆
        driver.findElement(By.className("W_btn_g")).click();
        Thread.sleep(15000);

        //勾选第一个商家的所有商品，这里的xpath地址因人而异，根据你的淘宝购物车修改J_Order_s_XXXX，的ID
        //driver.findElement(By.xpath("//*[@id=\"J_Order_s_2201456724924_1\"]/div[1]/div/label")).click();

        //勾选全部
        driver.findElement(By.xpath("//*[@id=\"J_SelectAll2\"]/div[1]/label")).click();
        Thread.sleep(1000);
        //结算
        driver.findElement(By.id("J_Go")).click();
        Thread.sleep(2000);
        //使用默认地址，确认购买（提交订单）
        driver.findElement(By.className("go-btn")).click();
        //等个15秒，让支付宝完成安全检测
        //Thread.sleep(15000);
        //换为你的支付密码
        //driver.findElement(By.id("payPassword_rsainput")).sendKeys(new String[]{"111111"});
        //Thread.sleep(1000);
        //确认支付
        //driver.findElement(By.id("J_authSubmit")).click();
        try {
            driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
